<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018-10-08
 * Time: 18:25
 */
namespace app\admin\controller;

use app\admin\model\AdminUser;
use app\admin\model\Excel;
use app\admin\model\Forward;
use app\admin\model\News;
use app\admin\model\System;
use app\admin\model\User;
use think\Db;
use think\Request;

class Index
{
    /**加载首页
     * @return \think\response\Redirect|\think\response\View
     */
    public function index()
    {
        if(!session('adminuser')){
            return redirect('index/login');
        }
        $system = System::get('xitong');
//        return $system;
        return view("index",['data'=>session('adminuser'),'system'=>$system]);
    }
    /**加载退出接口
     * @return \think\response\Redirect
     */
    public function sign_out(){
        session('adminuser','');
        return redirect('index/login');
    }

    /**加载欢迎页面
     * @return \think\response\View
     */
    public function welcome()
    {
        $data = Db::name('occupation')->where('pid',0)->select();
        foreach ($data as $key=>$value){
            $data[$key]['shuliang'] = Db::name('user')->where('occupation',$value['id'])->count();
        }
        return view("map",['data'=>$data]);
    }
public function getwelcome(){
    $data = Db::name('occupation')->where('pid',0)->select();
    foreach ($data as $key=>$value){
        $data[$key]['shuliang'] = Db::name('user')->where('occupation',$value['id'])->count();
    }
    return $data;
}
    /**加载登录页面
     * @param Request $request
     * @return \think\response\View
     */
    public function login(Request $request){
        return view('login2');
    }

    /**加载课程分类列表
     * @param Request $request
     * @return \think\response\Redirect|\think\response\View
     */
    public function classification(Request $request){
        if(!session('adminuser')){
            return redirect('index/login');
        }
        $tiaojian = $request->param('tiaojian',null);
        if($tiaojian){
            $data = Db::name('classes')->where('class_name','like',"%$tiaojian%")->order('create_time desc')->select();
        }else{
            $data = Db::name('classes')->order('create_time desc')->select();
        }

        return view('classification',['data'=>$data,'tiaojian'=>$tiaojian]);
    }

    /**加载添加课程分类页面
     * @return \think\response\View
     */
    public function create_class(){
        return view('create_class');
    }

    /**编辑课程分类
     * @param Request $request
     * @return string|\think\response\View
     */
    public function edit_classes(Request $request){
        $id = $request->param('id',null);
        if(!$id){
            return '请输入要编辑的分类';
        }
        $data = Db::name('classes')->where('id',$id)->find();
        return view('edit_classes',['data'=>$data]);
    }

    /** 加载课程分支
     * @return \think\response\View
     */
    public function branch(Request $request){
        $tiaojian = $request->param('tiaojian',null);
        if($tiaojian){
            $data = Db::view('classes','*')
                ->view('branch','*','branch.tables_class=classes.id','right')
                ->where('branch.branch_name','like',"%$tiaojian%")
                ->whereOr('classes.class_name','like',"%$tiaojian%")
                ->order('branch.tables_class desc')
                ->limit(10)
                ->select();
            $datarow = Db::view('classes','*')
                ->view('branch','*','branch.tables_class=classes.id','right')
                ->where('branch.branch_name','like',"%$tiaojian%")
                ->whereOr('classes.class_name','like',"%$tiaojian%")
                ->count();
        }else{
            $data = Db::view('classes','*')
                ->view('branch','*','branch.tables_class=classes.id','right')
                ->order('branch.tables_class desc')
                ->limit(10)
                ->select();
            $datarow = Db::view('classes','*')
                ->view('branch','*','branch.tables_class=classes.id','right')
                ->count();
        }
        return view('branch',['data'=>$data,'tiaojian'=>$tiaojian,'datarow'=>$datarow]);
    }

    /**加载课程分支列表
     * @return \think\response\View
     */
    public function create_branch(){
        $data = Db::name('classes')->order('create_time desc')->select();
        return view('create_branch',['data'=>$data]);
    }

    /**加载编辑课程分支
     * @param Request $request
     * @return string|\think\response\View
     */
    public function edit_branch(Request $request){
        $id = $request->param('id',null);
        if(!$id){
            return '请输入要编辑的课程分支';
        }
        $data = Db::view('classes','*')
            ->view('branch','*','branch.tables_class=classes.id','right')
            ->where('branch.id',$id)
            ->find();
        $class = Db::name('classes')->select();
//        echo '<pre>';print_r($class);exit;
        return view('edit_branch',['data'=>$data,'class'=>$class]);
    }

    /**加载题库列表
     * @return \think\response\View
     */
    public function question_bank(Request $request){
        $three_levelid = $request->param('three_level',null);
//        return $three_levelid;
        $pages = $request->param('page',1);
        $limit = $request->param('limit',10);
        $thisThree_level = [];
        $class = Db::name('classes')->select();
        if($three_levelid){
            $thisThree_level = Db::name('three_level')->where('id',$three_levelid)->find();
            $page = new Page();
            $data = $page->question_bank($three_levelid,$limit,$pages);
            $branch = Db::name('branch')->where('tables_class',$thisThree_level['classes_id'])->select();
            $three_level = Db::name('three_level')->where('branchid',$thisThree_level['branchid'])->select();
        }else{
            $branch = [];
            $three_level = [];
            if($class){
                $branch = Db::name('branch')->where('tables_class',$class[0]['id'])->select();
                if($branch){
                    $three_level = Db::name('three_level')->where('branchid',$branch[0]['id'])->select();
                }
            }
            $page = new Page();
            $data = [];
            if($three_level){
                $data = $page->question_bank($three_level[0]['id']);
                $thisThree_level = $three_level[0];
            }
        }
        if(!$data){
            $data['row'] = 0;
            $data['data'] = [];
        }
        $type = Db::name('situation')->select();
        foreach ($data['data'] as $key=>$value){
            foreach ($type as $values){
                if($values['id']==$value['type']){
                    $data['data'][$key]['type'] = $values['situation_name'];
                }
            }
        }
//        echo '<pre>';print_r($data);exit;
        return view('question_bank',['class'=>$class,'branch'=>$branch,'three_level'=>$three_level,'data'=>$data['data'],'row'=>$data['row'],'thisThree_level'=>$thisThree_level]);
    }

    /**加载添加题目页面
     * @param Request $request
     * @return \think\response\View
     */
    public function create_question_bank(Request $request){
        $class = Db::name('classes')->select();
        $situation = Db::name('situation')->select();
        return view('create_question_bank',['class'=>$class,'situation'=>$situation]);
    }

    /**加载题目编辑
     * @param Request $request
     * @return \think\response\View
     */
    public function edit_question_bank(Request $request){
        $id = $request->param('id',null);
        $data     = Db::name('bank')->json(['answer'])->where('id',$id)->find();
        $array = ["A","B","C","D","E","F","G"];
        $data['right_key'] = $array[$data['right_key']];
        $situation = Db::name('situation')->select();
        return view('edit_question_bank',['data'=>$data,'situation'=>$situation]);
    }

    /**加载导入题目页面
     * @return \think\response\View
     */
    public function daoru(){
        $class = Db::name('classes')->select();
        $situation = Db::name('situation')->select();
        return view('daoru',['class'=>$class,'situation'=>$situation]);
    }

    /**加载前台职业列表
     * @return \think\response\View
     */
    public function occupation(Request $request){
        $tiaojain = $request->param('tiaojian',null);
        if($tiaojain){
            $datas = Db::name('occupation')->where('occupation_name','like',"%$tiaojain%")->order('pid asc')->select();
            $datass  = Db::name('occupation')->select();
            $data = [];
            foreach ($datas as $key=>$value){
                if($value['pid']==0){
                    $value['pid'] = '最上级';
                    $data[] = $value;
                }else{
                    foreach ($datass as $values){
                        if($value['pid']==$values['id']){
                            $value['pid'] = $values['occupation_name'];
                            $data[] = $value;
                        }
                    }
                }
            }
        }else{
            $datas = Db::name('occupation')->order('pid asc')->select();
            $data = [];
            foreach ($datas as $key=>$value){
                if($value['pid']==0){
                    $value['pid'] = '最上级';
                    $data[] = $value;
                }else{
                    foreach ($datas as $values){
                        if($value['pid']==$values['id']){
                            $value['pid'] = $values['occupation_name'];
                            $data[] = $value;
                        }
                    }
                }
            }
        }
        return view('occupation',['data'=>$data,'tiaojian'=>$tiaojain]);
    }

    /**加载添加职业
     * @param Request $request
     * @return \think\response\View
     */
    public function create_occupation(Request $request){
        $data = Db::name('occupation')->select();
//        echo '<pre>';print_r($data);exit;
        return view('create_occupation',['data'=>$data]);
    }

    /**加载编辑职业
     * @param Request $request
     * @return \think\response\View
     */
    public function edit_occupation(Request $request){
        $id = $request->param('id',null);
        $class = Db::name('occupation')->select();
        $data = Db::name('occupation')->where('id',$id)->find();
//        echo '<pre>';print_r($data);exit;
        return view('edit_occupation',['data'=>$data,'class'=>$class]);
    }

    /**加载游戏等级列表
     * @param Request $request
     * @return \think\response\View
     */
    public function grade(Request $request){
        $tiaojian = $request->param('tiaojian',null);
        if($tiaojian){
            $data = Db::name('grade')->where('number','like',"%$tiaojian%")->order('number asc')->limit(10)->select();
            $datarow = Db::name('grade')->where('number','like',"%$tiaojian%")->count();
        }else{
            $data = Db::name('grade')->order('number asc')->limit(10)->select();
            $datarow = Db::name('grade')->count();
        }
        return view('grade',['data'=>$data,'tiaojian'=>$tiaojian,'datarow'=>$datarow]);
    }

    /**加载添加等级
     * @param Request $request
     * @return \think\response\View
     */
    public function create_grade(Request $request){
        return view('create_grade');
    }

    /**编辑等级
     * @param Request $request
     * @return \think\response\View
     */
    public function edit_grade(Request $request){
        $id = $request->param('id',null);
        $data = Db::name('grade')->where('id',$id)->find();
        return view('edit_grade',['data'=>$data]);
    }

    /**加载vip设置
     * @param Request $request
     * @return \think\response\View
     */
    public function vip_price(Request $request){
        $data = Db::name('vip_price')->order('vip_price asc')->select();
        foreach ($data as $key=>$value){
            if($value['vip_time']==30*24*3600){
                $data[$key]['vip_time'] = '一个月';
            }elseif ($value['vip_time']==183*24*3600){
                $data[$key]['vip_time'] = '半年';
            }elseif($value['vip_time']==365*24*3600){
                $data[$key]['vip_time'] = '一年';
            }elseif ($value['vip_time']==10*365*24*3600){
                $data[$key]['vip_time'] = '十年';
            }
        }
        return view('vip_price',['data'=>$data]);
    }

    /**加载添加vip
     * @param Request $request
     * @return \think\response\View
     */
    public function create_vip_price(Request $request){
        return view('create_vip_price');
    }

    /**加载编辑vip
     * @param Request $request
     * @return \think\response\View
     */
    public function edit_vip_price(Request $request){
        $id = $request->param('id',null);
        $data = Db::name('vip_price')->where('id',$id)->find();
        return view('edit_vip_price',['data'=>$data]);
    }

    /**加载第三级分类
     * @param Request $request
     * @return \think\response\View
     */
    public function three_level(Request $request){
        $classid = $request->param('classid',null);
        $branchid = $request->param('branch',null);


        $class = Db::name('classes')->select();
        if($classid){
            $thisClass = Db::name('classes')  ->where('id',$classid)->find();
        }elseif(!$classid&&$class){
            $thisClass = $class[0];
        }else{
            $thisClass = [];
        }

        $branch = [];
        if($thisClass){
            $branch = Db::name('branch')->where('tables_class',$thisClass['id'])->select();
        }
        if($branchid){
            $thisBranch = Db::name('branch')->where('id',$branchid)->find();
        }else{
            if($branch){
                $thisBranch = $branch[0];
            }else{
                $thisBranch = [];
            }
        }
        $three_level = [];
        if($thisBranch){
            $three_level = Db::name('three_level')->where('branchid',$thisBranch['id'])->select();
        }
        return view('three_level',['class'=>$class,'branch'=>$branch,'three_level'=>$three_level,'thisClass'=>$thisClass,'thisBranch'=>$thisBranch]);
    }

    /**加载添加第三级分类
     * @return \think\response\View
     */
    public function create_three_level(Request $request){
        $class = Db::name('classes')->select();
        $branch = [];
        if($class){
            $branch = Db::name('branch')->where('tables_class',$class[0]['id'])->select();
        }
        return view('create_three_level',['class'=>$class,'branch'=>$branch]);
    }

    /**编辑第三级分类
     * @param Request $request
     * @return \think\response\View
     */
    public function edit_three_level(Request $request){
        $id = $request->param('id',null);
        $data = Db::name('three_level')->where('id',$id)->find();
        return view('edit_three_level',['data'=>$data]);
    }

    /**加载体现点设置页面
     * @param Request $request
     * @return \think\response\View
     */
    public function tixiandian(Request $request){
        $tiaojian = $request->param('tiaojian',null);
        if($tiaojian){
            $data = Db::view('three_level','*')
                ->view('branch','branch_name','branch.id=three_level.branchid','left')
                ->view('classes','class_name','classes.id=three_level.classes_id','left')
                ->where('three_level.spot','<>',0)
                ->where('three_level.three_level_name','like',"%$tiaojian%")
                ->select();
        }else{
            $data = Db::view('three_level','*')
                ->view('branch','branch_name','branch.id=three_level.branchid','left')
                ->view('classes','class_name','classes.id=three_level.classes_id','left')
                ->where('three_level.spot','<>',0)->select();
        }
        return view('tixiandian',['data'=>$data,'tiaojian'=>$tiaojian]);
    }

    /**加载添加提现点页面
     * @param Request $request
     * @return \think\response\View
     */
    public function create_tixiandian(Request $request){
        $class = Db::name('classes')->select();
        return view('create_tixiandian',['class'=>$class]);
    }
    public function edit_tixiandian(Request $request){
        $id = $request->param('id',null);
        $data = Db::view('three_level',true)
            ->view('classes','class_name','classes.id=three_level.classes_id')
            ->view('branch','branch_name','branch.id=three_level.branchid')
            ->where('three_level.id',$id)
            ->find();
        return view('edit_tixiandian',['data'=>$data]);
    }

    /**加载模式列表
     * @param Request $request
     * @return \think\response\View
     */
    public function situation(Request $request){
        $data = Db::name('situation')->select();
        return view('situation',['data'=>$data]);
    }

    /**加载添加模式页面
     * @param Request $request
     * @return \think\response\View
     */
    public function create_situation(Request $request){
        return view('create_situation');
    }

    /**加载修改模式
     * @param Request $request
     * @return \think\response\View
     */
    public function edit_situation(Request $request){
        $id = $request->param('id',null);
        $data = Db::name('situation')->where('id',$id)->find();
        return view('edit_situation',['data'=>$data]);
    }

    /**加载未解题目
     * @param Request $request
     * @return \think\response\View
     */
    public function weijietiku(Request $request){
        $limit = $request->param('limit',10);
        $page  = $request->param('page',1);
            $data = Db::view('bank',true)
                ->view('classes','class_name','bank.classes_id=classes.id','left')
                ->view('branch','branch_name','bank.branch_id=branch.id','left')
                ->view('three_level','three_level_name','bank.three_level_id=three_level.id','left')
                ->json(['answer'])
                ->where('bank.status',2)
                ->order('bank.three_level_id desc')
                ->limit(($page-1)*$limit,$limit)
                ->select();
            $datarow = Db::name('bank')
                ->where('status',2)
                ->count();
//            echo '<pre>';print_r($data);exit;
            return view('weijietiku',['data'=>$data,'datarow'=>$datarow]);
    }

    /**加载解答未解题目
     * @param Request $request
     * @return \think\response\View
     */
    public function edit_weijietiku(Request $request){
        $id = $request->param('id',null);
        $data     = Db::name('bank')
            ->json(['answer'])
            ->where('id',$id)
            ->find();
        return view('edit_weijietiku',['data'=>$data]);
    }

    /**加载未审核题库
     * @param Request $request
     * @return \think\response\View
     */
    public function weishenghe(Request $request){
        $limit = $request->param('limit',10);
        $page  = $request->param('page',1);
        $data = Db::view('bank',true)
            ->view('classes','class_name','bank.classes_id=classes.id','left')
            ->view('branch','branch_name','bank.branch_id=branch.id','left')
            ->view('three_level','three_level_name','bank.three_level_id=three_level.id','left')
            ->json(['answer'])
            ->where('bank.status','<>',2)
            ->where('bank.status','<>',1)
            ->order('bank.three_level_id desc')
            ->limit(($page-1)*$limit,$limit)
            ->select();
        $datarow = Db::name('bank')
            ->where('status','<>',2)
            ->where('status','<>',1)
            ->count();
        return view('weishenghe',['data'=>$data,'datarow'=>$datarow]);
    }

    /**加载前台单项设置
     * @param Request $request
     * @return \think\response\View
     */
    public function system(Request $request){
        $limit = $request->param('limit',10);
        $page  = $request->param('page',1);
        $tiaojian = $request->param('tiaojian',null);
        if($tiaojian){
            $data = Db::name('system')
                ->where('system_name','like',"%$tiaojian%")
                ->order('id desc')
                ->limit(($page-1)*$limit,$limit)
                ->select();
            $datarow = Db::name('system')
                ->where('system_name','like',"%$tiaojian%")
                ->order('id desc')
                ->count();
        }else{
            $data = Db::name('system')->order('id desc')->limit(($page-1)*$limit,$limit)->select();
            $datarow = Db::name('system')->order('id desc')->count();
        }
        return view('system',['data'=>$data,'datarow'=>$datarow,'tiaojian'=>$tiaojian]);
    }

    /**加载添加设置项
     * @param Request $request
     * @return \think\response\View
     */
    public function create_system(Request $request){
        return view('create_system');
    }

    /**加载编辑设置项
     * @param Request $request
     * @return \think\response\View
     */
    public function edit_system(Request $request){
        $id = $request->param('id',null);
        $data = Db::name('system')->where('id',$id)->find();
        return view('edit_system',['data'=>$data]);
    }

    /**加载后台权限页面
     * @param Request $request
     * @return \think\response\View
     */
    public function admin_power(Request $request){
        $tiaojian = $request->param('tiaojian',null);
        if(!AdminUser::Auth('all')){
            return '你没有权限';
        }
        if($tiaojian){
            $data = Db::name('admin_power')->where('power_name','like',"%$tiaojian%")->order('id desc')->select();
            $datarow = Db::name('admin_power')->where('power_name','like',"%$tiaojian%")->count();
        }else{
            $data = Db::name('admin_power')->order('id desc')->select();
            $datarow = Db::name('admin_power')->count();
        }
        return view('admin_power',['data'=>$data,'tiaojian'=>$tiaojian,'datarow'=>$datarow]);
    }

    /**加载添加后台权限页面
     * @param Request $request
     * @return \think\response\View
     */
    public function create_admin_power(Request $request){
        if(!AdminUser::Auth('all')){
            return '你没有权限';
        }
        return view('create_admin_power');
    }

    /**加载编辑后台权限页面
     * @param Request $request
     * @return \think\response\View
     */
    public function edit_admin_power(Request $request){
        if(!AdminUser::Auth('all')){
            return '你没有权限';
        }
        $id = $request->param('id',null);
        $data = Db::name('admin_power')->where('id',$id)->find();
        return view('edit_admin_power',['data'=>$data]);
    }

    /**加载后台用户页面
     * @param Request $request
     * @return string|\think\response\View
     */
    public function admin_user(Request $request){
        $tiaojian = $request->param('tiaojian',null);
        if(!AdminUser::Auth('all')){
            return '你没有权限';
        }
        if($tiaojian){
            $data = Db::view('admin_user',true)
                ->view('admin_power','power_name','admin_power.id=admin_user.admin_power','left')
                ->where('admin_user|admin_nickname|phone','like',"%$tiaojian%")
                ->select();
        }else{
            $data = Db::view('admin_user',true)
                ->view('admin_power','power_name','admin_power.id=admin_user.admin_power')
                ->select();
        }
        return view('admin_user',['data'=>$data,'tiaojian'=>$tiaojian]);
    }

    /**加载添加后台用户
     * @param Request $request
     * @return string|\think\response\View
     */
    public function create_admin_user(Request $request){
        if(!AdminUser::Auth('all')){
            return '你没有权限';
        }
        $data = Db::name('admin_power')->select();
        return view('create_admin_user',['data'=>$data]);
    }

    /**加载修改后台用户页面
     * @param Request $request
     * @return \think\response\View
     */
    public function edit_admin_user(Request $request){
        $id =$request->param('id',null);
        $data = Db::name('admin_user')->where('id',$id)->find();
        $admin_power = Db::name('admin_power')->select();
        return view('edit_admin_user',['data'=>$data,'admin_power'=>$admin_power]);
    }

    /**加载前台用户列表页面
     * @param Request $request
     * @return \think\response\View
     */
    public function user(Request $request){
        $tiaojian = $request->param('tiaojian',null);
        $page = $request->param('page',1);
        $limit = $request->param('limit',10);
        if($tiaojian){
            $data = User::get()->where('user.user|user.user_name|user.nickname','like',"%$tiaojian%")
                ->order('user.id desc')
                ->limit(($page-1)*$limit,$limit)
                ->select();
            $datarow = User::get()->where('user.user|user.user_name|user.nickname','like',"%$tiaojian%")
                ->count();
        }else{
            $data = User::get()
                ->order('user.id desc')
                ->limit(($page-1)*$limit,$limit)
                ->select();
            $datarow = User::get()
                ->count();
        }
        return view('user',['data'=>$data,'datarow'=>$datarow,'tiaojian'=>$tiaojian]);
    }

    /**加载用户消息列表
     * @param Request $request
     * @return \think\response\View
     */
    public function news(Request $request){
        $tiaojian = $request->param('tiaojian',null);
        $limit = $request->param('limit',10);
        $page = $request->param('page',1);
        if($tiaojian){
            $data = News::get()->where('user.user|user.nickname|user.user_name','like',"%$tiaojian%")
                ->where('user.status',0)
                ->order('news.create_time desc')
                ->limit(($page-1)*$limit,$limit)
                ->select();
            $datarow = News::get()->where('user.user|user.nickname|user.user_name','like',"%$tiaojian%")
                ->where('user.status',0)
                ->count();
        }else{
            $data = News::get()
                ->where('user.status',0)
                ->order('news.create_time desc')
                ->limit(($page-1)*$limit,$limit)
                ->select();
            $datarow = News::get()
                ->where('user.status',0)
                ->count();
        }
        return view('news',['data'=>$data,'datarow'=>$datarow,'tiaojian'=>$tiaojian]);
    }

    /**加载用户订单
     * @param Request $request
     * @return \think\response\View
     */
    public function forward(Request $request){
        $tiaojian = $request->param('tiaojian',null);
        $limit = $request->param('limit',10);
        $page = $request->param('page',1);
        $start_times = $request->param('start_time',null);
        $end_times = $request->param('end_time',null);
        $type     = $request->param('type',1);
        $status   = $request->param('status',0);
//        echo '<pre>';print_r($request->param());exit;
        if($start_times){
            $start_time = strtotime($start_times);
            if($end_times){
                $end_time = strtotime($end_times);
            }else{
                $end_time = time();
            }
        }else{
            if($end_times){
                $end_time = strtotime($end_times);
                $start_time = 0;
            }else{
                $start_time = 0;
                $end_time = time();
            }
        }
        $end_time = $end_time+86400;
        if($tiaojian){
            $data = Forward::get()
                ->where('user.user|user.user_name|user.nickname','like',"%$tiaojian%")
                ->where('forward.type',$type)
                ->where('forward.status',$status)
                ->where('forward.create_time','>',$start_time)
                ->where('forward.create_time','<',$end_time)
                ->order('forward.end_time desc')
                ->limit(($page-1)*$limit,$limit)
                ->select();
            $datarow = Forward::get()
                ->where('user.user|user.user_name|user.nickname','like',"%$tiaojian%")
                ->where('forward.type',$type)
                ->where('forward.status',$status)
                ->where('forward.create_time','>',$start_time)
                ->where('forward.create_time','<',$end_time)
                ->count();
        }else{
            $data = Forward::get()
                ->where('forward.type',$type)
                ->where('forward.status',$status)
                ->where('forward.create_time','>',$start_time)
                ->where('forward.create_time','<',$end_time)
                ->order('forward.end_time desc')
                ->limit(($page-1)*$limit,$limit)
                ->select();
            $datarow = Forward::get()
                ->where('forward.type',$type)
                ->where('forward.status',$status)
                ->where('forward.create_time','>',$start_time)
                ->where('forward.create_time','<',$end_time)
                ->count();
        }
        return view('forward',['data'=>$data,'datarow'=>$datarow,'tiaojian'=>$tiaojian,'type'=>$type,'status'=>$status,'start_time'=>$start_times,'end_time'=>$end_times]);
    }

    /**下载订单流水
     * @param Request $request
     */
    public function daochu(Request $request){
        $tiaojian = $request->param('tiaojian',null);
        $start_times = $request->param('start_time',null);
        $end_times = $request->param('end_time',null);
        $type     = $request->param('type',1);
        $status   = $request->param('status',0);
        if($start_times){
            $start_time = strtotime($start_times);
            if($end_times){
                $end_time = strtotime($end_times);
            }else{
                $end_time = time();
            }
        }else{
            if($end_times){
                $end_time = strtotime($end_times);
                $start_time = 0;
            }else{
                $start_time = 0;
                $end_time = time();
            }
        }
        $end_time = $end_time+86400;
        if($tiaojian){
            $data = Forward::get()
                ->where('user.user|user.user_name|user.nickname','like',"%$tiaojian%")
                ->where('forward.type',$type)
                ->where('forward.status',$status)
                ->where('forward.create_time','>',$start_time)
                ->where('forward.create_time','<',$end_time)
                ->order('forward.end_time desc')
                ->select();
        }else{
            $data = Forward::get()
                ->where('forward.type',$type)
                ->where('forward.status',$status)
                ->where('forward.create_time','>',$start_time)
                ->where('forward.create_time','<',$end_time)
                ->order('forward.end_time desc')
                ->select();
        }
        foreach ($data as $key=>$value){
            if($value['type']==1){
                $data[$key]['type'] = '提现';
            }else{
                $data[$key]['type'] = '充值';
            }
            $data[$key]['create_time'] = date('Y-m-d H:i:s',$value['create_time']);
            $data[$key]['end_time'] = date('Y-m-d H:i:s',$value['end_time']);
            if($value['status']==1){
                $data[$key]['status'] = '已处理';
            }else{
                $data[$key]['status'] = '未处理';
            }
        }
        $array = [
            'id'=>'ID',
            'order_number'=>'订单号',
            'user'        =>'用户名',
            'user_name'        =>'真实姓名',
            'open_id'        =>'open_id',
            'weixin'        =>'微信号',
            'phone'        =>'手机号码',
            'type'        =>'订单类型',
            'number'        =>'订单金额',
            'create_time'        =>'创建时间',
            'end_time'        =>'最晚到账时间',
            'status'        =>'状态',
        ];
        Excel::dataToExcel($data,$array,'订单流水');
    }

    /**加载vip用户列表
     * @param Request $request
     * @return \think\response\View
     */
    public function vipuser(Request $request){
        $tiaojian = $request->param('tiaojian',null);
        $limit = $request->param('limit',10);
        $page = $request->param('page',1);
        if($tiaojian){
            $data = User::get()
                ->where('user.vip','>',0)
                ->where('user.user|user.nickname|user.user_name|vip_price.vip_name|vip_price.vip_icon|vip_price.vip_price','like',"%$tiaojian%")
                ->order('vip_price.vip_icon desc')
                ->limit(($page-1)*$limit,$limit)
                ->select();
            $datarow = User::get()
                ->where('user.vip','>',0)
                ->where('user.user|user.nickname|user.user_name|vip_price.vip_name|vip_price.vip_icon|vip_price.vip_price','like',"%$tiaojian%")
                ->count();
        }else{
            $data = User::get()
                ->where('user.vip','>',0)
                ->order('vip_price.vip_icon desc')
                ->limit(($page-1)*$limit,$limit)
                ->select();
            $datarow = User::get()
                ->where('user.vip','>',0)
                ->count();
        }
        return view('vipuser',['data'=>$data,'datarow'=>$datarow,'tiaojian'=>$tiaojian]);
    }
}